package com.sitia.jd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.enums.BusinessType;
import com.sitia.system.domain.MxProvince;
import com.sitia.system.service.IMxProvinceService;
import com.sitia.common.utils.poi.ExcelUtil;

/**
 * 省份Controller
 * 
 * @author sitia
 * @date 2023-07-16
 */
@RestController
@RequestMapping("/jd/province")
public class MxProvinceController extends BaseController
{
    @Autowired
    private IMxProvinceService mxProvinceService;

    /**
     * 查询省份列表
     */
    //@PreAuthorize("@ss.hasPermi('jd:province:list')")
    @GetMapping("/list")
    public AjaxResult list(MxProvince mxProvince)
    {

        List<MxProvince> list = mxProvinceService.selectMxProvinceList(mxProvince);
        return AjaxResult.success(list);
    }

    /**
     * 导出省份列表
     */
   // @PreAuthorize("@ss.hasPermi('jd:province:export')")
    @Log(title = "省份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxProvince mxProvince)
    {
        List<MxProvince> list = mxProvinceService.selectMxProvinceList(mxProvince);
        ExcelUtil<MxProvince> util = new ExcelUtil<MxProvince>(MxProvince.class);
        util.exportExcel(response, list, "省份数据");
    }

    /**
     * 获取省份详细信息
     */
    //@PreAuthorize("@ss.hasPermi('jd:province:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mxProvinceService.selectMxProvinceById(id));
    }

    /**
     * 新增省份
     */
    @PreAuthorize("@ss.hasPermi('jd:province:add')")
    @Log(title = "省份", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxProvince mxProvince)
    {
        return toAjax(mxProvinceService.insertMxProvince(mxProvince));
    }

    /**
     * 修改省份
     */
    @PreAuthorize("@ss.hasPermi('jd:province:edit')")
    @Log(title = "省份", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxProvince mxProvince)
    {
        return toAjax(mxProvinceService.updateMxProvince(mxProvince));
    }

    /**
     * 删除省份
     */
    @PreAuthorize("@ss.hasPermi('jd:province:remove')")
    @Log(title = "省份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mxProvinceService.deleteMxProvinceByIds(ids));
    }
}
